home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
Palettes
/
SwitchBox
/
SwitchBox.m
< prev
next >
Wrap
Text File
|
1995-06-12
|
5KB
|
245 lines
/*
** Copyright (C) 1992 Ronin Consulting, Inc.
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; version 1.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#import "SwitchBox.h"
#import <appkit/Matrix.h>
#import <appkit/color.h>
#import <dpsclient/psops.h>
#import <objc/List.h>
#define MAXPANEL 10
@interface SwitchBox(Private) /* No one should have to see this.... */
- setPanel0: anObject;
- setPanel1: anObject;
- setPanel2: anObject;
- setPanel3: anObject;
- setPanel4: anObject;
- setPanel5: anObject;
- setPanel6: anObject;
- setPanel7: anObject;
- setPanel8: anObject;
- setPanel9: anObject;
@end
@implementation SwitchBox
/*
* Boxes are rather stubborn about painting a gray background so
* I set the box as transparent and then fill the rect with the
* color of the windows background.
*/
- drawSelf:(const NXRect *)rects :(int)rectCount
{
float r, g, b;
NXConvertColorToRGB([window backgroundColor], &r, &g, &b);
PSsetrgbcolor(r,g,b);
NXRectFill(rects);
return [super drawSelf: rects : rectCount]; /* finish up by calling the real drawSelf */
}
- free
{
if(origContentView) /* if I have been switching contents resore my original */
contentView = origContentView;
if(panelList) /* if I have created a panelList free it */
[panelList free];
return [super free];
}
- initFrame:(const NXRect *)frameRect
{
[super initFrame:frameRect];
origContentView = nil;
defaultPanel = -1;
[self setTitlePosition: NX_NOTITLE];
[self setBorderType: NX_BEZEL];
return self;
}
- switchToTagOf: sender;
{
if([sender isKindOf: [Matrix class]])
[self switchTo: [[sender selectedCell] tag]];
else
[self switchTo: [sender tag]];
return self;
}
- switchTo: (int) number;
{
if(delegate && [delegate respondsTo: @selector(willSwitchTo:)])
if(![delegate willSwitchTo: number])
return self;
if(number < 0 || number >= MAXPANEL)
return self;
[self setContentView: [panelList objectAt: number]];
if([self contentView])
{
[self setBorderType: NX_NOBORDER];
// bFlags.transparent = YES;
[self display];
if(delegate && [delegate respondsTo: @selector(didSwitchTo:)])
[delegate didSwitchTo: number];
}
return self;
}
- setDefaultPanel: (int) number
{
defaultPanel = number;
return self;
}
- (int) defaultPanel
{
return defaultPanel;
}
- setPanel: anObject at: (int) index
{
if(index < 0 || index >= MAXPANEL)
return self;
if(!panelList)
{
int x = MAXPANEL;
panelList = [[List alloc] initCount: MAXPANEL];
while(x--)
[panelList addObject: [self contentView]];
origContentView = contentView; /* copy aside my original contentView */
}
[panelList replaceObjectAt: index with: [anObject contentView]];
if(index == defaultPanel)
[self switchTo: defaultPanel];
return self;
}
- setDelegate: anObject
{
delegate = anObject;
return self;
}
- delegate
{
return delegate;
}
- (const char *)getInspectorClassName
{
return "SwitchBoxInspector";
}
-read:(NXTypedStream *) s
{
[super read:s];
NXReadTypes(s, "i", &defaultPanel);
return self;
}
-write:(NXTypedStream *) s
{
[super write:s];
NXWriteTypes(s, "i", &defaultPanel);
return self;
}
@end /* SwitchBox */
@implementation SwitchBox(Private)
- setPanel0: anObject
{
[self setPanel: anObject at: 0];
return self;
}
- setPanel1: anObject
{
[self setPanel: anObject at: 1];
return self;
}
- setPanel2: anObject
{
[self setPanel: anObject at: 2];
return self;
}
- setPanel3: anObject
{
[self setPanel: anObject at: 3];
return self;
}
- setPanel4: anObject
{
[self setPanel: anObject at: 4];
return self;
}
- setPanel5: anObject
{
[self setPanel: anObject at: 5];
return self;
}
- setPanel6: anObject
{
[self setPanel: anObject at: 6];
return self;
}
- setPanel7: anObject
{
[self setPanel: anObject at: 7];
return self;
}
- setPanel8: anObject
{
[self setPanel: anObject at: 8];
return self;
}
- setPanel9: anObject
{
[self setPanel: anObject at: 9];
return self;
}
@end /* SwitchBox(Private) */